package com.company.cloud.club.modules.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.company.cloud.club.modules.db.dao.RecommendCardMapper;
import com.company.cloud.club.modules.db.domain.RecommendCard;
import com.company.cloud.club.modules.db.domain.UserInfo;
import com.company.cloud.club.modules.service.RecommendService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Set;

/**
 * *****************************************************************************
 * <p>
 * 功能名           ：com.company.cloud.club.modules.service.impl
 * 系统名           ：
 * <p>
 * *****************************************************************************
 * Modification History
 * <p>
 * Date        Name                    Reason for Change
 * ----------  ----------------------  -----------------------------------------
 * 2020/7/18     zhangxu                 Created
 */
@Service
public class RecommendServiceImpl extends ServiceImpl<RecommendCardMapper, RecommendCard> implements RecommendService {

    @Autowired
    private RecommendCardMapper recommendCardMapper;

    @Override
    public List<RecommendCard> queryByType(String type) {
        return recommendCardMapper.selectTopAll(type);
    }

    @Override
    public Integer countComment(String id) {
        Integer count = 0;
        List<RecommendCard> cardList = recommendCardMapper.selectByParentId(id);
        count += cardList.size();
        for (RecommendCard card : cardList) {
            if (card.getIsPublish() != 2) {
                continue;
            }
            List<RecommendCard> subCardList = recommendCardMapper.selectByParentId(card.getId());
            count += subCardList.size();
        }
        return count;
    }

    @Override
    public List<RecommendCard> selectAllDynamic(Integer isPublish, Integer begin, Integer pageSize) {
        if (isPublish == 1) {
            return recommendCardMapper.selectAllDynamic(begin, pageSize);
        }
        return recommendCardMapper.selectAllDynamics(isPublish, begin, pageSize);
    }

    @Override
    public int countAllDynamic(Integer isPublish) {
        if (isPublish == 1) {
            return recommendCardMapper.countAllDynamic();
        }
        return recommendCardMapper.countAllDynamics(isPublish);
    }

    @Override
    public List<RecommendCard> selectAllDynamicToday(Integer isPublish, Integer begin, Integer pageSize) {
        return recommendCardMapper.selectAllDynamicsToday(isPublish, begin, pageSize);
    }


    @Override
    public List<RecommendCard> queryByParentId(String id) {
        return recommendCardMapper.selectByParentId(id);
    }

    @Override
    public List<RecommendCard> selectTopAll(String type) {
        return recommendCardMapper.selectTopAll(type);
    }

    @Override
    public boolean removeRecom(String id) {
        return recommendCardMapper.removeById(id);
    }

    @Override
    public List<RecommendCard> selectByTypeAndSuggest(String type, int sug) {
        return recommendCardMapper.selectByTypeAndSuggest(type, sug);
    }

    @Override
    public List<RecommendCard> selectMyFollow(Set<String> collList, Integer begin, Integer pageSize) {
        return recommendCardMapper.selectMyFollow(collList, begin, pageSize);
    }

    @Override
    public List<UserInfo> pageUserByParentId(String parentId, Integer begin, Integer pageSize) {
        return recommendCardMapper.pageUserByParentId(parentId, begin, pageSize);
    }

    @Override
    public Integer pageCountByParentId(String activityId) {
        return recommendCardMapper.pageCountByParentId(activityId);
    }

    @Override
    public boolean publishRecom(String id) {
        return recommendCardMapper.publishRecom(id);
    }

    @Override
    public int suggestRecom(String id) {
        RecommendCard recommendCard = recommendCardMapper.selectById(id);
        Integer isSuggest = recommendCard.getIsSuggest();
        if (isSuggest == 0) {
            recommendCard.setIsSuggest(1);
        } else {
            recommendCard.setIsSuggest(0);
        }
        recommendCardMapper.updateById(recommendCard);
        return recommendCard.getIsSuggest();
    }

    @Override
    public List<RecommendCard> pageByParentId(String id, Integer begin, Integer pageSize) {
        return recommendCardMapper.pageByParentId(id, begin, pageSize);
    }

    @Override
    public int countMyFollow(Set<String> collList) {
        return recommendCardMapper.countMyFollow(collList);
    }

    @Override
    public List<RecommendCard> selectMyFriend(Set<String> collList, Integer begin, Integer pageSize) {
        return recommendCardMapper.selectMyFriend(collList, begin, pageSize);
    }

    @Override
    public int countMyFriend(Set<String> collList) {
        return recommendCardMapper.countMyFriend(collList);
    }

    @Override
    public List<RecommendCard> selectByClubId(String clubId, Integer begin, Integer pageSize) {
        return recommendCardMapper.selectByClubId(clubId, begin, pageSize);
    }

    @Override
    public int countByClubId(String clubId) {
        return recommendCardMapper.countByClubId(clubId);
    }

    @Override
    public List<RecommendCard> pageByUserId(Integer uid, Integer begin, Integer pageSize) {
        return recommendCardMapper.pageByUserId(uid, begin, pageSize);
    }

    @Override
    public int countByUserId(Integer uid) {
        return recommendCardMapper.countByUserId(uid);
    }

    @Override
    public List<RecommendCard> pageEssenceAndClub(String clubId, Integer begin, Integer pageSize) {
        return recommendCardMapper.pageEssenceAndClub(clubId, begin, pageSize);
    }

    @Override
    public int countEssenceAndClub(String clubId) {
        return recommendCardMapper.countEssenceAndClub(clubId);
    }

    @Override
    public List<RecommendCard> selectByFileTypeAndSuggest(String type, int sug) {
        return recommendCardMapper.selectByFileTypeAndSuggest(type, sug);
    }

    @Override
    public List<RecommendCard> noticeList(String id) {
        return recommendCardMapper.noticeList(id);
    }

    @Override
    public int updateEssenceRecom(String id) {
        RecommendCard recommendCard = recommendCardMapper.selectById(id);
        Integer isEssence = recommendCard.getIsEssence();
        if (isEssence == 0) {
            recommendCard.setIsEssence(1);
        } else {
            recommendCard.setIsEssence(0);
        }
        recommendCardMapper.updateById(recommendCard);
        return recommendCard.getIsEssence();
    }

}